package com.xun.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xun.bean.Course;
import com.xun.bean.User;
import com.xun.mapper.CourseMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Package: com.xun.controller
 * @ClassName: UserController
 * @Author: Think
 * @CreateTime: 2021/6/15 16:05
 * @Description:
 */
@RestController
public class CourseController {
    @Autowired
    private CourseMapper courseMapper;

    // 新增操作
    @PostMapping("/addCourse")
    public Integer addCourse(@RequestBody Course course){
        return courseMapper.insert(course);
    }

    // 更新操作
    @PostMapping("/updateCourse")
    public Integer updateCourse(@RequestBody Course course){
        // course:version=1，模拟更新前查到了version
        QueryWrapper<Course> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("course_id", course.getCourseId());
        // UPDATE zx_course SET course_name=?, version=? WHERE (course_id = ? AND version = ?)
        return courseMapper.update(course, queryWrapper);
    }
}
